using UnityEngine;

public class DailyBonusUI : MonoBehaviour
{
	private GameObject uiobj;

	public DailyBonusItem[] bonusitems;

	public int daycount;

	public int alreadgetcount;

	public UIEventListener closebtn;

	public Animation scaleanima;
	public Animator animator;

	private bool isshow;

	private void Start()
	{
		closebtn.onClick = OnClickcloseBtn;
	}

	public void init_ui_info()
	{
		daycount = Platform.GetBonusCount();
		if (daycount == -1)
		{
			alreadgetcount = Platform.GetBonusAlreadyGot();
			alreadgetcount %= 7;
		}
		else
		{
			if (daycount == 0 && MenuPlayerprefs.instance.bonusisfirst > 1)
			{
				MenuPlayerprefs.instance.setbonusfirst(0);
			}
			alreadgetcount = daycount;
		}
		if (MenuPlayerprefs.instance.bonusisfirst > 0)
		{
			for (int i = 0; i < bonusitems.Length; i++)
			{
				bonusitems[i].enable(i, MenuDataController.instance.firstbonusdata[i], daycount, alreadgetcount);
			}
		}
		else
		{
			for (int j = 0; j < bonusitems.Length; j++)
			{
				bonusitems[j].enable(j, MenuDataController.instance.bonusdata[j], daycount, alreadgetcount);
			}
		}
		//scaleanima.Stop();
		animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		Invoke("animplay", Time.deltaTime * 2f);
	}

	public void animplay()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void enable()
	{
		if (uiobj == null)
		{
			uiobj = base.gameObject;
		}
		init_ui_info();
		NGUITools.SetActive(uiobj, state: true);
		isshow = true;
	}

	public void OnClickcloseBtn(GameObject btn)
	{
		if (isshow)
		{
			isshow = false;
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
			/* scaleanima["PopWinAnimation"].time = scaleanima.clip.length;
			scaleanima["PopWinAnimation"].speed = -1f;
			scaleanima.Play(); */
			animator.SetTrigger("popWin2");
			Invoke("disable", animator.runtimeAnimatorController.animationClips[0].length);
		}
	}

	public void disable()
	{
		MenuBackController.instance.BackMenuUIstate();
		NGUITools.SetActive(uiobj, state: false);
	}
}
